﻿using System;
using System.Data;
using System.Collections.Generic;

namespace ZHDJ.MobileInterface
{
    public partial class GetATMNotMatchMassageDetail : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            GetATMNotMatchMassageDetailOutParam result = new GetATMNotMatchMassageDetailOutParam();
            GetATMNotMatchMassageDetailInParam param = new GetATMNotMatchMassageDetailInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as GetATMNotMatchMassageDetailInParam;

                if (string.IsNullOrEmpty(param.SaveID) && string.IsNullOrEmpty(param.TakeID))
                {
                    result.code = "0";
                    result.desc = "捐助ID和求助ID不能同时为空。";
                    isFlag = false;
                }
                if (string.IsNullOrEmpty(param.IsUseCurrent))
                {
                    if (isFlag)
                    {
                        #region Save
                        if (!string.IsNullOrEmpty(param.SaveID))
                        {
                            SaveDataList Saveitem;
                            DataTable dt = InterfaceHelper.QuerySaveInfo(param.SaveID);
                            result.SaveDataEX.total_pages = 0;
                            if (dt.Rows.Count > 0)
                            {
                                foreach (var dr in dt.Rows)
                                {
                                    Saveitem = new SaveDataList();
                                    Saveitem.STitle = dt.Rows[0]["Name"].ToString();
                                    Saveitem.SBranchSave = dt.Rows[0]["BranchName"].ToString();
                                    Saveitem.SBranchAddressSave = dt.Rows[0]["BranchAddress"].ToString();
                                    Saveitem.SBranchContactSave = dt.Rows[0]["BranchContact"].ToString();
                                    Saveitem.SBranchContactPersonSave = dt.Rows[0]["BranchContactPerson"].ToString();
                                    Saveitem.SCreatebySave = dt.Rows[0]["CreateByName"].ToString();
                                    Saveitem.SCreatebyAddressSave = dt.Rows[0]["CreatebyAddress"].ToString();
                                    Saveitem.SCreatebyContactSave = dt.Rows[0]["CreatebyContact"].ToString();

                                    Saveitem.SCreateTimeSave = Convert.ToDateTime(dt.Rows[0]["CreateTime"].ToString()).ToString("yyyy-MM-dd");
                                    Saveitem.SDescriptionSave = dt.Rows[0]["Description"].ToString();
                                    Saveitem.SNameSave = dt.Rows[0]["Name"].ToString();
                                    Saveitem.SPurposesDescriptionSave = dt.Rows[0]["PurposesDescription"].ToString();
                                    Saveitem.SThingCountSave = dt.Rows[0]["ThingCount"].ToString();
                                    Saveitem.SPurposesSave = dt.Rows[0]["PurposesName"].ToString();
                                    Saveitem.SSaveModusSave = dt.Rows[0]["SaveModusName"].ToString();
                                    Saveitem.SStatusSave = dt.Rows[0]["StatusName"].ToString();
                                    Saveitem.SThingTypeSave = dt.Rows[0]["ThingTypeName"].ToString();
                                    Saveitem.STitularSave = dt.Rows[0]["TitularName"].ToString();
                                    Saveitem.SIsEndTimeSave = dt.Rows[0]["IsEndTimeName"].ToString();
                                    Saveitem.SEndTimeSave = Convert.ToDateTime(dt.Rows[0]["EndTime"].ToString()).ToString("yyyy-MM-dd");
                                    Saveitem.SBranchName = dt.Rows[0]["BranchName"].ToString();
                                    result.SaveDataEX.list.Add(Saveitem);
                                }
                            }
                        }
                        #endregion
                        #region Take
                        else if (!string.IsNullOrEmpty(param.TakeID))
                        {
                            TakeDataList Takeitem;
                            DataTable dt = InterfaceHelper.QueryTakeInfo(param.TakeID);
                            result.TakeDataEx.total_pages = 0;
                            foreach (var dr in dt.Rows)
                            {
                                Takeitem = new TakeDataList();
                                if (param.IsLoveActivity == "1")
                                {
                                    Takeitem.TCreatebySaveName = "爱心组织";
                                    Takeitem.TCreatebySave = dt.Rows[0]["BranchName"].ToString();
                                    Takeitem.TCreatebyAddressSave = dt.Rows[0]["BranchAddress"].ToString();
                                }
                                else
                                {
                                    Takeitem.TCreatebySaveName = "求助人";
                                    Takeitem.TCreatebySave = dt.Rows[0]["CreateByName"].ToString() + "[" + dt.Rows[0]["CreateByBranchName"].ToString() + "]";
                                    Takeitem.TCreatebyAddressSave = dt.Rows[0]["CreatebyAddress"].ToString();
                                }
                                Takeitem.TTitle = dt.Rows[0]["Name"].ToString();
                                Takeitem.TCreateTimeSave = Convert.ToDateTime(dt.Rows[0]["CreateTime"].ToString()).ToString("yyyy-MM-dd");
                                Takeitem.TDescriptionSave = dt.Rows[0]["Description"].ToString();
                                Takeitem.TNameSave = dt.Rows[0]["Name"].ToString();
                                Takeitem.TThingCountSave = dt.Rows[0]["ThingCount"].ToString();
                                Takeitem.TStatusSave = dt.Rows[0]["StatusName"].ToString();
                                Takeitem.TThingTypeSave = dt.Rows[0]["ThingTypeName"].ToString();
                                Takeitem.TEndTimeSave = Convert.ToDateTime(dt.Rows[0]["EndTime"].ToString()).ToString("yyyy-MM-dd");
                                result.TakeDataEx.list.Add(Takeitem);
                            }
                        }
                        #endregion
                    }
                }
                else if (param.IsUseCurrent == "Save")//针对求助信息进行捐助
                { 
                
                
                }
                else if (param.IsUseCurrent == "Take")//针对捐助信息进行求助
                { }
                else
                {
                    result.code = "0";
                    result.desc = "传输错误，请检查传值正确与否，联系管理员！";
                    isFlag = false;
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetATMNotMatchMassageDetail", SerializeHelper.JsonSerializer<GetATMNotMatchMassageDetailInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<GetATMNotMatchMassageDetailInParam, GetATMNotMatchMassageDetailOutParam>();
            else
                SafeProcessRequest<GetATMNotMatchMassageDetailInParam, GetATMNotMatchMassageDetailOutParam>();
        }
    }
    #region 请求参数
    public class GetATMNotMatchMassageDetailInParam
    {
        /// <summary>
        /// 捐助ID
        /// </summary>
        public string SaveID
        { get; set; }

        /// <summary>
        /// 求助ID
        /// </summary>
        public string TakeID
        { get; set; }

        /// <summary>
        /// 组织或个人
        /// </summary>
        public string IsLoveActivity
        { get; set; }

        /// <summary>
        /// 是否使用当前信息进行配对   Save 针对求助信息进行捐助  Take 针对捐助信息进行求助
        /// </summary>
        public string IsUseCurrent
        { get; set; }
    }
    #endregion


    #region 结果参数
    public class GetATMNotMatchMassageDetailOutParam
    {
        public GetATMNotMatchMassageDetailOutParam()
        {
            code = "1";
            desc = "操作成功";
            SaveDataEX = new SaveData();
            TakeDataEx = new TakeData();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        public SaveData SaveDataEX
        { get; set; }

        public TakeData TakeDataEx
        { get; set; }

    }
    public class SaveData
    {
        public SaveData()
        {
            total_pages = 0;
            list = new List<SaveDataList>();
        }

        public List<SaveDataList> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    public class SaveDataList
    {
        #region

        public string STitle
        { get; set; }
        /// <summary>
        /// 捐助人
        /// </summary>
        public string SCreatebySave
        { get; set; }
        /// <summary>
        /// 联系方式
        /// </summary>
        public string SCreatebyContactSave
        { get; set; }
        /// <summary>
        /// 联系地址
        /// </summary>
        public string SCreatebyAddressSave
        { get; set; }

        /// <summary>
        /// 捐助组织
        /// </summary>
        public string SBranchSave
        { get; set; }

        /// <summary>
        /// 组织联系人
        /// </summary>
        public string SBranchContactPersonSave
        { get; set; }

        /// <summary>
        /// 联系方式
        /// </summary>
        public string SBranchContactSave
        { get; set; }

        /// <summary>
        /// 组织地址
        /// </summary>
        public string SBranchAddressSave
        { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public string SThingTypeSave
        { get; set; }

        /// <summary>
        /// 捐助名义
        /// </summary>
        public string STitularSave
        { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string SNameSave
        { get; set; }
        /// <summary>
        /// 所属组织
        /// </summary>
        public string SBranchName
        { get; set; }
        /// <summary>
        /// 资助用途
        /// </summary>
        public string SPurposesSave
        { get; set; }
        
        /// <summary>
        /// 数量
        /// </summary>
        public string SThingCountSave
        { get; set; }

        /// <summary>
        /// 用途说明
        /// </summary>
        public string SPurposesDescriptionSave
        { get; set; }
        /// <summary>
        /// 设置有效期
        /// </summary>
        public string SIsEndTimeSave
        { get; set; }
        /// <summary>
        /// 捐助形式
        /// </summary>
        public string SSaveModusSave
        { get; set; }
        /// <summary>
        /// 有效期
        /// </summary>
        public string SEndTimeSave
        { get; set; }

        /// <summary>
        /// 捐助时间
        /// </summary>
        public string SCreateTimeSave
        { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public string SStatusSave
        { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string SDescriptionSave
        { get; set; }
        #endregion
    }

    public class TakeData
    {
        public TakeData()
        {
            total_pages = 0;
            list = new List<TakeDataList>();
        }

        public List<TakeDataList> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    public class TakeDataList
    {
        #region

        public string TTitle
        { get; set; }
        /// <summary>
        /// 捐助组织or捐助人
        /// </summary>
        public string TCreatebySaveName
        { get; set; }
        /// <summary>
        /// 组织名称or匿名
        /// </summary>
        public string TCreatebySave
        { get; set; }
        /// <summary>
        /// 联系地址
        /// </summary>
        public string TCreatebyAddressSave
        { get; set; }
        /// <summary>
        /// 类型
        /// </summary>
        public string TThingTypeSave
        { get; set; }
        /// <summary>
        /// 有效期
        /// </summary>
        public string TEndTimeSave
        { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string TNameSave
        { get; set; }
        /// <summary>
        /// 数量
        /// </summary>
        public string TThingCountSave
        { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public string TStatusSave
        { get; set; }
        /// <summary>
        /// 求助时间
        /// </summary>
        public string TCreateTimeSave
        { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string TDescriptionSave
        { get; set; }
        #endregion
    }
    #endregion
}